package com.hsav.kcxb.fragment.setting;

import android.app.DatePickerDialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.hsav.kcxb.R;

import java.util.Calendar;

/**
 * Created by zhao on 2017/2/11.
 */

public class NightFragment extends Fragment {

    private SwitchCompat mInstantSwitch;
    private SwitchCompat mAlarmSwitch;
    private TextView mInstantTx;
    private TextView mAlarmTx;
    private RelativeLayout mBeginLayout;
    private RelativeLayout mEndLayout;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.frag_night_layout, container, false);
        initView(rootView);
        return rootView;
    }

    private void initView(View rootView) {
        mInstantTx = (TextView) rootView.findViewById(R.id.tx_instant);
        mAlarmTx = (TextView) rootView.findViewById(R.id.tx_alarm);

        mInstantSwitch = (SwitchCompat) rootView.findViewById(R.id.switch_instant);
//        //设置滑块的图片
//        mInstantSwitch.setThumbResource(R.color.color_green);
//        //设置轨道的图片
//        mInstantSwitch.setTrackResource(R.color.colorPrimary);

        mInstantSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    mInstantTx.setText("开启");
                } else {
                    mInstantTx.setText("关闭");
                }
            }
        });
        mAlarmSwitch = (SwitchCompat) rootView.findViewById(R.id.switch_alarm);
        mAlarmSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    mAlarmTx.setText("开启");
                } else {
                    mAlarmTx.setText("关闭");
                }
            }
        });

        mBeginLayout = (RelativeLayout) rootView.findViewById(R.id.rl_night_begin);
        mBeginLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
//                    @Override
//                    public void onDateSet(DatePicker view, int year, int month, int day) {
//                        // TODO Auto-generated method stub
//                        int  mYear = year;
//                        int mMonth = month;
//                        int mDay = day;
//                        //更新EditText控件日期 小于10加0
//                        dateEdit.setText(new StringBuilder().append(mYear).append(-)
//                                .append((mMonth + 1) < 10 ? 0 + (mMonth + 1) : (mMonth + 1))
//                                .append(-)
//                                .append((mDay < 10) ? 0 + mDay : mDay) );
//                    }
//                }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
//                        calendar.get(Calendar.DAY_OF_MONTH) ).show();
                DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                        Toast.makeText(getActivity(), "year=" + year + ",month" + month + ",day=" + dayOfMonth, Toast.LENGTH_LONG).show();
                    }
                }, 2017, 3, 23);
                datePickerDialog.show();

            }
        });

        mEndLayout = (RelativeLayout) rootView.findViewById(R.id.rl_night_end);
        mEndLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                DatePicker datePicker = new DatePicker(getActivity());
//                datePicker.setVisibility(View.VISIBLE);
                DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity());
                datePickerDialog.show();
            }
        });
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }
}
